package com.hah.steamDemo.demo;

import com.hah.steamDemo.entiy.TestObject;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 30909
 */
public class SrreamOperation {

    static List<TestObject> list = Arrays.asList(
      new TestObject("Ron","M",10,"3090930041@qq.com",false),
            new TestObject("KDS","W",10,"kds@qq.com",false),
            new TestObject("BoDuo","W",30,"boduo@163.com",false),
            new TestObject("CangJin","W",10,"cangjin@gmail.com",false),
            new TestObject("XiaoZe","W",30,"xiaoze@hotmail.com",true),
            new TestObject("James","M",10,"leblonjames@hotmail.com",true),
            new TestObject("Allen","M",50,"allen.lei@tfschange.com",true),
            new TestObject("Smith","M",10,"jr.smith@cel.com",true),
            new TestObject("Wade","M",20,"dw.wade@cel.com",true),
            new TestObject("Wade","M",20,"dw.wade@cel.com",false)
    );



    public static void main(String[] args) {
        //筛选出为 turn 的人名字
//        List<TestObject> leaders = getLeader();
//        leaders.stream().forEach(leader->System.out.println(leader.getName()));
        // 该方法是将数组转化成List集合的方法。
//        List<String> strList = Arrays.asList("AA", "BB", "CC", "BB", "CC", "AA", "AA");
        //distinct 去重方法
//        List<String> collect = strList.stream().distinct().collect(Collectors.toList());
//        for (String s : collect) {
//            System.out.println("s. = " + s);
//        }、
        // 筛选各异的元素
//        List<Integer> numbers = Arrays.asList(1, 2, 1, 3, 3, 2, 4);
//        numbers.stream()
//                //去重
//                .distinct()
//                //过滤表达式
//                .filter(i-> i%2 ==0)
//                .forEach(System.out::println);

        //截断流
//        list.stream()
//                //值等于M
//                .filter(u->u.getSex().equals("M"))
//                //取三个
//                .limit(3)
//                .sorted(Comparator.comparing(TestObject::getAge))
//                .skip(1)
//                //只要名字
//                .forEach(u -> System.out.println(u.getAge()));

//        list.stream()
//                .map(TestObject::getName)
////                .map(String::length)
//                .collect(Collectors.toList())
//                .forEach(System.out::println);


//        if (list.stream().anyMatch(u->u.getName().equals("Ron"))){
//            System.out.println("找到了 Ron ");
//        }

//        if (list.stream().anyMatch(u -> u.getAge() >=10)){
//            System.out.println(" 都大于 10 岁了");
//        }else {
//            System.out.println(" 小于10 ");
//        }

//        list.stream()
//                .filter(u -> u.getName().equals("Allen"))
//                .findAny()
//                .ifPresent( u -> System.out.println(u.getName()));
        List<TestObject> allen = list.stream()
                .filter(s -> s.getName().equals("Allen")).collect(Collectors.toList());
        System.out.println(allen);


    }
    public static List<TestObject> getLeader(){
        return list.stream().filter(TestObject::isMsg).collect(Collectors.toList());
    }


}
